unit FrmConfiguracoes1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls, StdCtrls, Registry;

type
  TFrmConfiguracoes = class(TForm)
    PageControl1: TPageControl;
    ttsdbeexplorer: TTabSheet;
    ckcdbedetalhes: TCheckBox;
    trvconfiguracoes: TTreeView;
    Panel1: TPanel;
    Button2: TButton;
    Button1: TButton;
    Splitter1: TSplitter;
    ttseditorsql: TTabSheet;
    ckcdbetempschema: TCheckBox;
    ckcdbeparametrofunction: TCheckBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure trvconfiguracoesClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmConfiguracoes: TFrmConfiguracoes;

implementation

uses UFuncao;

{$R *.dfm}

procedure TFrmConfiguracoes.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TFrmConfiguracoes.Button1Click(Sender: TObject);
var
  reg: TRegistry;
begin
  reg := TRegistry.Create();
  reg.OpenKey(reg_raiz, true);

  // dbe = dbexplorer
  reg.WriteBool('dbe_atributos', ckcdbedetalhes.Checked);
  reg.WriteBool('dbe_schemainterno', ckcdbetempschema.Checked);
  reg.WriteBool('dbe_param_function', ckcdbeparametrofunction.Checked);

  reg.CloseKey;
  reg.Free;

  Close;
end;

procedure TFrmConfiguracoes.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TFrmConfiguracoes.FormCreate(Sender: TObject);
var
  reg: TRegistry;
begin
  // Esconder Abas
  ttsdbeexplorer.TabVisible := False;
  ttseditorsql.TabVisible   := False;

  PageControl1.ActivePage := ttsdbeexplorer;

  // Preencher Conforme Registro
  reg := TRegistry.Create();
  reg.OpenKeyReadOnly(reg_raiz);

  // Atributos do DBE Explorer ('dbe_')
  if reg.ValueExists('dbe_atributos')      then ckcdbedetalhes.Checked := reg.ReadBool('dbe_atributos');
  if reg.ValueExists('dbe_schemainterno')  then ckcdbetempschema.Checked := reg.ReadBool('dbe_schemainterno');
  if reg.ValueExists('dbe_param_function') then ckcdbeparametrofunction.Checked := reg.ReadBool('dbe_param_function');

  reg.CloseKey;
  reg.Free;
end;

procedure TFrmConfiguracoes.trvconfiguracoesClick(Sender: TObject);
begin
  if trvconfiguracoes.Selected.Text = 'DB Explorer' then PageControl1.ActivePage := ttsdbeexplorer;
  if trvconfiguracoes.Selected.Text = 'Editor SQL'  then PageControl1.ActivePage := ttseditorsql;
end;

end.
